package de.reondo.jos;

import org.jgrapht.graph.DefaultWeightedEdge;


public class JarDependencyEdge extends DefaultWeightedEdge implements IWitness<String> {

    /**
     * 
     */
    private static final long serialVersionUID = 8155456071962836293L;
    private String tgt;
    private String src;
    private String witness;

    public JarDependencyEdge(String src, String tgt) {
        this.src = src;
        this.tgt = tgt;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((src == null) ? 0 : src.hashCode());
        result = prime * result + ((tgt == null) ? 0 : tgt.hashCode());
        return result;
    }

    public int getEdgeWeight() {
        return (int) getWeight();
    }
    
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        JarDependencyEdge other = (JarDependencyEdge) obj;
        if (src == null) {
            if (other.src != null)
                return false;
        } else if (!src.equals(other.src))
            return false;
        if (tgt == null) {
            if (other.tgt != null)
                return false;
        } else if (!tgt.equals(other.tgt))
            return false;
        return true;
    }

    public void setWitness(String occurrence) {
        this.witness = occurrence;
    }

    /**
     * Yields the "witness" for this edge, which should be set to the occurrence of an
     * edge in the class graph from which the jar graph originated.
     * @return a string describing the witness
     */
    public String getWitness() {
        return witness;
    }

}
